// 纯JS省市区三级联动
// 2011-11-30 by http://www.cnblogs.com/zjfree
var channelInit = function (_oneChannel, _twoChannel, _thrChannel, defaultoneChannel, defaulttwoChannel, defaultArea) {
    var oneChannel = document.getElementById(_oneChannel);
    var twoChannel = document.getElementById(_twoChannel);
    var thrChannel = document.getElementById(_thrChannel);

    function cmbSelect(cmb, str) {
        for (var i = 0; i < cmb.options.length; i++) {
            if (cmb.options[i].value == str) {
                cmb.selectedIndex = i;
                return;
            }
        }
    }

    function cmbAddOption(cmb, str, obj) {
        var option = document.createElement("OPTION");
        cmb.options.add(option);
        option.innerText = str;
        option.value = str;
        option.obj = obj;
    }

    function changetwoChannel() {
        thrChannel.options.length = 0;
        if (twoChannel.selectedIndex == -1) return;
        var item = twoChannel.options[twoChannel.selectedIndex].obj;
        for (var i = 0; i < item.areaList.length; i++) {
            cmbAddOption(thrChannel, item.areaList[i], null);
        }
        cmbSelect(thrChannel, thrChanneli);
    }

    function changeoneChannel() {
        twoChannel.options.length = 0;
        twoChannel.onchange = null;
        if (oneChannel.selectedIndex == -1) return;
        var item = oneChannel.options[oneChannel.selectedIndex].obj;
        for (var i = 0; i < item.citiesList.length; i++) {
            cmbAddOption(twoChannel, item.citiesList[i].name, item.citiesList[i]);
        }
        cmbSelect(twoChannel, twoChanneli);
        changetwoChannel();
        twoChannel.onchange = changetwoChannel;
    }

    for (var i = 0; i < ChannelList.length; i++) {
        cmbAddOption(oneChannel, ChannelList[i].name, ChannelList[i]);
    }
    cmbSelect(oneChannel, oneChanneli);
    changeoneChannel();
    oneChannel.onchange = changeoneChannel;
}